﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LegtionMVVM
{
    public partial class FormCommanEditor : Form
    {
        public string Scripts { get; set; }
        Control component=null;
        public FormCommanEditor(Control component)
        {
            InitializeComponent();
            this.component = component;
            
        }
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            //component.GetType().GetEvents
            labelControlName.Text = component.Name;
            rtbBindings.Text = Scripts;

            List<string> listEventsName = Source.GetTypeEventsName(component.GetType());
            if (listEventsName != null)
            {
                listEventsName.ForEach(yy => comboBoxProperty.Items.Add(yy));
       
                comboBoxProperty.SelectedIndex = 0;
            }
        }

        private void FormCommanEditor_HelpButtonClicked(object sender, CancelEventArgs e)
        {
            FormScriptHelp frm = new FormScriptHelp();
            frm.ShowDialog();
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            rtbBindings.AppendText((rtbBindings.Lines.Length>0?"\n":"")+ comboBoxProperty.SelectedItem + "=");            
        }
 

        private void buttonOK_Click(object sender, EventArgs e)
        {
            Scripts = rtbBindings.Text;
            DialogResult = DialogResult.OK;
        }
    }
}
